#include <iostream>
#include <cstring>

using namespace std;

const int maxn = 10010;

int main() {
	char str[maxn];
	int hash_table[1010] = {0};
	int n, team, id, score, max = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d-%d %d", &team, &id, &score);
		hash_table[team] += score;
	}

	for (int i = 0; i < 1001; i++) {
		if (hash_table[max] < hash_table[i]) {
			max = i;
		}
	}
	printf("%d %d", max, hash_table[max]);

	return 0;
}
